from flask_wtf.file import FileRequired, FileAllowed
from wtforms import StringField, IntegerField, PasswordField, FloatField, FieldList, FileField
from wtforms.validators import DataRequired, length, Email, Regexp, NumberRange, EqualTo
from wtforms import ValidationError
from app.validators.filebase import FileBaseForm
from app.verify.AlismsService import SMSService
from app.libs.enums import ClientTypeEnum, Scope_dict
from app.models.user import User
from app.validators.base import BaseForm as Form


class ClientForm(Form):
    account = StringField(validators=[DataRequired(message='不允许为空'), length(
        min=5, max=32
    )])
    password = StringField()
    type = IntegerField(validators=[DataRequired()])
    wx_open_id = StringField(default='')
    wx_union_id = StringField(default='')
    scene = IntegerField(default=0)

    def validate_type(self, value):
        try:
            client = ClientTypeEnum(value.data)
        except ValueError as e:
            raise e
        self.type.data = client


class UpdateUnionIdForm(Form):
    code = StringField(default='')


class UpdateGzhOpenIdForm(Form):
    unionid = StringField(default='')
    gzh_open_id = StringField(default='')
    writer = IntegerField(default=0)


class UpdateGzhOpenIdAndUnlockForm(Form):
    unionid = StringField(default='')
    gzh_open_id = StringField(default='')
    order_number = StringField(default='')


class WxClientForm(ClientForm):
    wx_open_id = StringField(default='')
    wx_profile = StringField(default='')
    wx_union_id = StringField(default='')


class UserInfoForm(Form):
    scene = StringField(default='')


class UpdateSharedUserForm(Form):
    action = StringField(default='')
    fromuser = StringField(default='')
    scene = StringField(default='')

    # def validate_alipay_account(self, field):
    #     if User.query.filter_by(alipay_account=field.data).filter(User.id != self.id.data).first():
    #         raise ValidationError('支付宝账号已存在')
    #
    # def validate_qq_number(self, field):
    #     if User.query.filter_by(qq_number=field.data).filter(User.id != self.id.data).first():
    #         raise ValidationError('QQ号已存在')
    #
    # def validate_phone_number(self, field):
    #     if User.query.filter_by(phone_number=field.data).filter(User.id != self.id.data).first():
    #         raise ValidationError('手机号已存在')


class TokenForm(Form):
    token = StringField(validators=[DataRequired()])


class SMSForm(Form):
    phone_number = StringField(validators=[DataRequired()])


class AvatorForm(Form):
    avatar = StringField(validators=[DataRequired(message='验证码必填')])


def GzhSubscribeForm(Form):
    gzh_open_id = StringField()
    union_id = StringField()


class CurrentSceneIdForm(Form):
    currentSceneId = StringField()
    

class UnlockReportNumberFrom(Form):
    order_number = StringField()
